<?php
header("Content-type: text/html; charset=utf-8");

require_once('json.inc.php');
require('../dbconnect.inc.php');

$use_opt = false;

if($_GET['type'] == 'opt')
{
	$use_opt = true;
}

$rs = $dbh->query('select e_id, name from events');

$alldb = $rs->fetchAll(PDO::FETCH_ASSOC);

foreach( $alldb as $key => $val)
{
	if ($use_opt)
	{
		echo "<option value='" . $val['e_id'] . "'>". $val['name'] ."</option>\n";
	}
	else
	{
		$response[$key]['id'] = $val['e_id'];
		$response[$key]['name'] = $val['name'];
	}
}

if (!$use_opt)
{
	echo json_encode($response);
}

?>
